﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
//using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.Config;
using System.Xml.Linq;
using ThreeByte.Media;

namespace ThreeByte.ActiveDeck.Content
{
    /// <summary>
    /// Interaction logic for CurrentSlidePreview.xaml
    /// </summary>
    public partial class CurrentSlidePreview : UserControl, IPreviewControl
    {
        private CurrentSlideConfig _config;
        public PageConfig Config { get; set; }

        public CurrentSlidePreview(CurrentSlideConfig config) {
            InitializeComponent();
            _config = config;
            Config = config;
            DataContext = config;
            _config.Refresh();
        }

        public PresentationPageConfiguration GetPageConfiguration() {
            XNamespace ns = Service.ServiceConfiguration.NAMESPACE;

            PresentationPageConfiguration newPage = new PresentationPageConfiguration();
            
            XElement pageNode = new XElement(ns + "Page", new XAttribute("ID", _config.PageId),
                                            new XAttribute("Type", "CurrentSlide"),
                                            new XAttribute("Transition", _config.Transition));

            //Disable the Interactive Elements
            LayerRenderer.Hide();
            //Snap the Background
            this.UpdateLayout();
            GraphicResource imageResource = new GraphicResource(ImageUtil.SaveToBitmapSource(LayoutRoot, ImageUtil.DefaultPortraitSize), null, ImageType.JPEG);
            newPage.Resources[imageResource.ID] = imageResource;
            XElement imageNode = new XElement(ns + "Image", new XAttribute("ResourceID", imageResource.ID));
            pageNode.Add(imageNode);

            newPage.ConfigXml = pageNode;
            return newPage;
        }

    }
}
